// VBConversions Note: VB project level imports
using System.Diagnostics;
using System;
using System.Xml.Linq;
using System.Windows.Forms;
using System.Collections;
using System.Drawing;
using Microsoft.VisualBasic;
using System.Data;
using System.Collections.Generic;
using Microsoft.VisualBasic.Compatibility;
using System.Linq;
// End of VB project level imports


namespace 喷码数据生成工具
{
	public partial class frm_SearchWindow
	{
		frm_TextEdit frm;
#region 窗体构造函数
		public frm_SearchWindow(frm_TextEdit frm)
		{
			
			// 此调用是 Windows 窗体设计器所必需的。
			InitializeComponent();
			
			// 在 InitializeComponent() 调用之后添加任何初始化。
			frm = frm;
		}
		public frm_SearchWindow()
		{
			
			// 此调用是 Windows 窗体设计器所必需的。
			InitializeComponent();
			
			// 在 InitializeComponent() 调用之后添加任何初始化。
			
		}
		public frm_SearchWindow(string sText)
		{
			// 此调用是 Windows 窗体设计器所必需的。
			InitializeComponent();
			
			// 在 InitializeComponent() 调用之后添加任何初始化。
			TB_SearchValue.Text = sText;
		}
		public frm_SearchWindow(frm_TextEdit frm, string gText)
		{
			
			// 此调用是 Windows 窗体设计器所必需的。
			InitializeComponent();
			
			// 在 InitializeComponent() 调用之后添加任何初始化。
			frm = frm;
			TB_SearchValue.Text = gText;
		}
#endregion
public frm_TextEdit FatherForm
		{
			get
			{
				return frm;
			}
			set
			{
				frm = value;
			}
		}
		long SearchIndex;
		public void frm_SearchReplace_Load(System.Object sender, System.EventArgs e)
		{
			SearchIndex = 0;
			RB_DirectionDown.Checked = true;
		}
		
		public void Btn_Search_Click(System.Object sender, System.EventArgs e)
		{
			string SearchValue = CommFunction.TranslateText(TB_SearchValue.Text);
			System.Windows.Forms.RichTextBoxFinds SearchOption = new System.Windows.Forms.RichTextBoxFinds();
			if (CB_UpowerdLower.Checked)
			{
				SearchOption = RichTextBoxFinds.MatchCase;
			}
			else
			{
				SearchOption = RichTextBoxFinds.None;
			}
			frm_TextEdit with_1 = frm;
			if (RB_DirectionDown.Checked)
			{
				if (SearchIndex < 0)
				{
					SearchIndex = 0;
				}
				SearchIndex = with_1.TextBox.Find(SearchValue, SearchIndex, with_1.TextBox.TextLength, SearchOption);
				if (SearchIndex > 0)
				{
					with_1.TextBox.SelectionStart = SearchIndex;
					with_1.TextBox.SelectionLength = SearchValue.Length;
					SearchIndex = System.Convert.ToInt64(SearchIndex + SearchValue.Length);
				}
				else
				{
					MessageBox.Show(this, "已搜索至文档结束！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
				}
			}
			else
			{
				if (SearchIndex <= 0)
				{
					SearchIndex = with_1.TextBox.TextLength;
				}
				SearchIndex = FindbyPresve(SearchValue);
				if (SearchIndex > 0)
				{
					with_1.TextBox.SelectionStart = SearchIndex;
					with_1.TextBox.SelectionLength = SearchValue.Length;
				}
				else
				{
					MessageBox.Show(this, "已搜索至文档起始位置！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
				}
			}
		}
		private long FindbyPresve(string value)
		{
			string ToSearch = frm.TextBox.Text.Substring(0, SearchIndex);
			int Result = -1;
			if (CB_UpowerdLower.Checked)
			{
				Result = ToSearch.LastIndexOf(value);
			}
			else
			{
				Result = ToSearch.ToLower().LastIndexOf(value.ToLower());
			}
			return Result;
		}
		public void Btn_Cancel_Click(System.Object sender, System.EventArgs e)
		{
			this.Close();
		}
	}
}
